import Common from '../common'
var Js = Common('thirdApp')
export default {
	name: 'thirdApp',
	mixins: [Js],
	components: {},
	data() {
		return {
			fields: [{
					key: 'id',
					label: 'ID',
					application: [],
					componentName: 'sls-input',
					listType: '',
					width: 50
				},
				{
					key: 'name',
					label: '项目名称',
					application: ['添加'],
					componentName: 'sls-input',
					listType: 'normal',
					header_search: {
						componentName: 'sls-input',
						style: 'width:160px;margin-right:2px;',
						placeholder: '请输入项目名称',
						clearable: true,
						defaultValue: '',
						optionDataName: '',
						changeFunc: function(val, self) {
							if (val) {
								self.searchItem.name = ['LIKE', ['%' + val + '%']];
							} else {
								delete self.searchItem.name;
							};
						},
					},
				},
				{
					key: 'price',
					label: '起送金额',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: 'distance',
					label: '配送距离（米）',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: 'one_level',
					label: '返奖励金金额',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: 'phone',
					label: '客服联系电话',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: "open1",
					label: '微信支付开关',
					application: ['编辑', '添加'],
					componentName: 'sls-select',
					optionsName: 'statusOptions',
					defaultProps: {
						label: 'text',
						value: 'value',
					},
				},
				{
					key: "open2",
					label: '货到付款开关',
					application: ['编辑', '添加'],
					componentName: 'sls-select',
					optionsName: 'statusOptions',
					defaultProps: {
						label: 'text',
						value: 'value',
					},
				},
				{
					key: "open3",
					label: '银行卡转账开关',
					application: ['编辑', '添加'],
					componentName: 'sls-select',
					optionsName: 'statusOptions',
					defaultProps: {
						label: 'text',
						value: 'value',
					},
				},
				{
					key: "open4",
					label: '二维码收款开关',
					application: ['编辑', '添加'],
					componentName: 'sls-select',
					optionsName: 'statusOptions',
					defaultProps: {
						label: 'text',
						value: 'value',
					},
				},
				{
					key: 'bank',
					label: '开户行',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: 'bank_name',
					label: '户名',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: 'card_no',
					label: '账号',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
				{
					key: 'bank_phone',
					label: '电话',
					application: ['编辑', '添加'],
					componentName: 'sls-input',
				},
        {
        	key: 'mainImg',
        	label: '客服微信二维码',
        	customSlot: 'mainImg',
        	application: ['编辑', '添加'],
        	componentName: 'upload',
        	limit: 10,
        	dialogStyle: 'width:90%'
        },
        {
        	key: 'bannerImg',
        	label: '收款码',
        	customSlot: 'bannerImg',
        	application: ['编辑', '添加'],
        	componentName: 'upload',
        	limit: 10,
        	dialogStyle: 'width:90%'
        },
				{
					key: 'create_time',
					label: '创建时间',
					listType: 'normal',
					placeholder: '请选择创建时间',
					header_search: {
						componentName: 'sls-date-time-range',
						style: 'width:160px;margin-right:2px;',
						start_placeholder: '创建开始时间',
						end_placeholder: '创建结束时间',
						changeFunc: function(value, self) {
							if (!value) {
								delete self.searchItem.create_time;
							} else {
								self.searchItem.create_time = ['between', value = value.map(function(e) {
									return e / 1000;
								})]
							};
						},
					},
					width: 200,
				},
				{
					label: '操作',
					listType: 'deal',
					width: 80
				},
			],
			// 按钮配置
			btn_info: [


				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'list',
					text: function(data) {
						return '编辑'
					},
					func: {
						apiName: function(self) {
							return "api_thirdAppUpdate"
						},
						formData: function(self) {
							return self.formData
						},
						postData: function(self) {
							var postData = {
								searchItem: {
									id: self.formData.id,
								},
								data: self.submitData
							}
							// console.log('self.submitData.time_range',new Date(new Date()),self.submitData.time_range[0]);
							if(self.submitData.time_range){
								postData.data.time_range = postData.data.time_range.join(',');
							}
							if(self.submitData.date_range){
								postData.data.date_range = postData.data.date_range.join(',');
							}
							console.log('postData',postData);
							return postData;
						}
					},
				},
				{
					type: 'danger',
					icon: 'delete',
					size: 'mini',
					funcType: 'submit',
					position: 'header',
					text: function(data) {
						return '删除选中'
					},
					func: {
						apiName: function(self) {
							return "api_thirdAppUpdate"
						},
						postData: function(self) {
							var deleteArray = [];
							for (var i = 0; i < self.selectionArray.length; i++) {
								deleteArray.push(self.selectionArray[i].id);
							};
							var postData = {
								searchItem: {
									id: ['in', deleteArray],
								},
								data: {
									status: -1
								}
							};
							return postData;
						}
					},
				},
				{
					type: 'info',
					icon: 'edit',
					size: 'mini',
					position: 'header',
					text: function(data) {
						return '添加'
					},
					func: {
						apiName: function(self) {
							return "api_thirdAppAdd"
						},
						formData: function(self) {
							var data = {
								login_name: '',
								password: '',
							};
							return data
						},
						postData: function(self) {
							var postData = {
								data: self.submitData
							};
							return postData;
						}
					},
				},
			],

			searchItem: {

			},
			startSearchItem: {

			},
			optionData: {
				labelOptions: [],
				statusOptions: [{
						text: '关闭',
						value: 0
					},
					{
						text: '开启',
						value: 1
					},
				],
			},
			otherData: {},
			UserInfo: {
				tableName: 'UserInfo',
				searchItem: {},
				key: 'user_no',
				middleKey: 'user_no',
				condition: 'in',
			},


		}

	},

	mounted() {
		const self = this;
		self.searchData = self.$$cloneForm(self.searchItem);
		this.init()
	},
	computed: {
		token: function() {
			return this.$store.getters.getToken
		}
	},
	methods: {

		/**
		 * 初始化
		 */
		init() {
			this.initMainData()
		},

		/**
		 * 列表主函数
		 */
		async initMainData(isNew) {

			const self = this;
			const postData = {};
			if (isNew) {
				self.paginate.currentPage = 1;
			};
			postData.paginate = self.$$cloneForm(self.paginate);
			postData.token = self.$store.getters.getToken;
			if (self.searchItem) {
				postData.searchItem = self.$$cloneForm(self.searchItem)
			};
			if (JSON.stringify(self.getBefore) != "{}") {
				postData.getBefore = self.$$cloneForm(self.getBefore);
			};

			var res = await self.$$api_thirdAppGet({
				data: postData
			});
			self.mainData = res.info.data;
			self.mainData[0].is_login = parseInt(self.mainData[0].is_login);
			if(self.mainData[0].date_range){
				self.mainData[0].date_range = [self.mainData[0].date_range.split(',')[0],self.mainData[0].date_range.split(',')[1]]
			}
			if(self.mainData[0].time_range){
				self.mainData[0].time_range = [self.mainData[0].time_range.split(',')[0],self.mainData[0].time_range.split(',')[1]]
			}

			console.log('mainData',self.mainData[0].time_range)
			self.paginate.count = res.info.total;

		},

	},


}
